﻿
@{
    ViewBag.Title = "修改密码";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}

@section Contents{
    <style>
        html {
            background-color: #FFF;
        }

        .layui-form-item .layui-input-inline {
            width: 300px;
        }

        .red {
            color: red;
        }
    </style>
}

<div id="page"></div>

<template id="tplPage">
    <div class="layui-form" lay-filter="layuiadmin-app-form-list" style="padding: 20px 30px;">
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>{{lang.Field.OldPassword}}：</label>
            <div class="layui-input-inline">
                <input type="password" name="OldPwd" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>{{lang.Field.NewPassword}}：</label>
            <div class="layui-input-inline">
                <input type="password" name="NewPwd1" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="red">*</span>{{lang.Field.NewPassword}}：</label>
            <div class="layui-input-inline">
                <input type="password" name="NewPwd2" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="text-align:left;padding-top: 20px;padding-left:110px;">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submit"><i class="layui-icon">&#xe605;</i>{{lang.Field.Submit}}</button>
        </div>
    </div>
</template>


@section Scripts{
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });

        setTimeout(function () {
            initLayui();
        }, 50);

        function initLayui() {
            layui.use(['form', 'layer', 'index'], function () {
                var layer = layui.layer,
                    form = layui.form;

                form.on('submit(submit)', function (data) {
                    var forms = data.field;
                    if (forms.NewPwd2.trim() != forms.NewPwd1.trim()) {
                        layer.msg("两次输入的新密码不一致", { icon: 5 });
                        return;
                    }

                    var loadId = layer.load();
                    $.ajax({
                        url: "/Settings/ModifyPassword",
                        data: {
                            oldPwd: forms.OldPwd.trim(),
                            newPwd: forms.NewPwd1.trim()
                        },
                        complete: function () {
                            layer.close(loadId);
                        },
                        success: function (res) {
                            if (res.ErrCode != 200) {
                                layer.msg(res.ErrMsg, { icon: 5 });
                                return;
                            }
                            layer.msg("修改成功，请重新登录！", { icon: 6, time: 1500 }, function () {
                                parent.location.href = "/Auth/Login";
                            });
                        }
                    });
                    return false;
                });
            });
        }
    </script>
}
